<template>
  <div>
    <el-dialog :title='title' :visible.sync="dialogFormVisible" @closed="$emit('update:activated', false)"
               width="1250px" top="5vh">
      <el-card>
        <div class="dialogStyle" style="display: flex;flex-direction: column;height: 500px;">
<!--          {{id}}-->
          <div v-for="(form,index) in formAll ">
            <div>
              <el-button  v-if="index==0"  type="primary" size="mini" class="btn-opt" plain @click="addOne">
                <i class="el-icon-circle-plus-outline"></i></el-button>
              <el-button  v-if="index!=0" type="primary" size="mini" class="btn-opt" plain @click="deleteOne(index)">
                <i class="el-icon-remove-outline"></i></el-button>
            </div>
            <el-form :inline="true" class="search-form search-form-normal" label-width="90px" ref="form"
                     :model="form" size="mini" :rules="rules">
              <el-form-item :label="$t('pageTable.MatterMaterialSpecificNumber')" prop="materialCode">
                <el-input :disabled="index==0" v-model="form.materialCode" class="search-form-item-input" style="width:160px" size="mini"
                          @blur="selectMaterialInfo(form.materialCode,index)" :maxlength="32" clearable></el-input>
                <!--<template slot="error" slot-scope="scope">-->
                <!--<div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
                <!--</template>-->
                <!--<div style="float: right;margin-right: 40px;"><el-button :disabled="form.materialCode==''" @click="selectMaterialInfo(form.materialCode)">{{$t('searchFrom.checkAndGet')}}</el-button></div>-->
              </el-form-item>
              <el-form-item :label="$t('pageTable.materialName')" prop="materialName">
                <el-input :disabled="index==0" v-model="form.materialName" class="search-form-item-input" style="width:160px" size="mini"
                          :maxlength="32" clearable></el-input>
                <!--<template slot="error" slot-scope="scope">-->
                <!--<div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
                <!--</template>-->
              </el-form-item>
              <el-form-item :label="$t('pageTable.contractNo')" prop="contractNo">
                <el-input :disabled="index==0" v-model="form.contractNo" class="search-form-item-input" style="width:160px" size="mini"
                          @blur="initInfoByContractNo(form.contractNo,index)" :maxlength="32" clearable></el-input>
                <!--<template slot="error" slot-scope="scope">-->
                <!--<div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
                <!--</template>-->
                <!--<div style="float: right;margin-right: 40px;"><el-button :disabled="form.contractNo==''" @click="initInfoByContractNo(form.contractNo)">{{$t('searchFrom.checkAndGet')}}</el-button></div>-->
              </el-form-item>
              <el-form-item :label="$t('pageTable.packingDate')" prop="packingDate">
                <el-date-picker
                  v-model="form.packingDate"
                  type="date"
                  :disabled="index==0"
                  style="width:160px"
                  value-format="yyyyMMddHHmmss">
                </el-date-picker>
                <!--<template slot="error" slot-scope="scope">-->
                <!--<div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
                <!--</template>-->
              </el-form-item>
              <el-form-item :label="$t('pageTable.departureDate')" prop="departureDate">
                <el-date-picker
                  v-model="form.departureDate"
                  type="date"
                  :disabled="index==0"
                  style="width:160px"
                  @blur="blurDepartureDate(index)"
                  value-format="yyyyMMddHHmmss">
                </el-date-picker>
                <!--<template slot="error" slot-scope="scope">-->
                <!--<div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
                <!--</template>-->
              </el-form-item>
              <el-form-item :label="$t('pageTable.TypeOfShipping')" prop="shippingMethods">
                <el-select :disabled="index==0"  v-model="form.shippingMethods" style="width: 160px" size="mini" clearable>
                  <el-option value=""></el-option>
                  <el-option
                    size="mini"
                    v-for="item in transportation"
                    :key="item.value"
                    :label="item.name"
                    :value="item.value">
                  </el-option>
                </el-select>
                <!--<template slot="error" slot-scope="scope">-->
                <!--<div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
                <!--</template>-->
              </el-form-item>
              <el-form-item :label="$t('pageTable.billNo')" prop="billNo">
                <el-input :disabled="index==0" v-model="form.billNo" class="search-form-item-input" style="width:160px" size="mini"
                          :maxlength="32" clearable></el-input>
                <!--<template slot="error" slot-scope="scope">-->
                <!--<div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
                <!--</template>-->
              </el-form-item>
              <el-form-item :label="$t('pageTable.containerSize')" prop="containerSize">
                <!--<el-input v-model="form.containerSize" class="search-form-item-input" style="width:160px" size="mini"-->
                <!--:maxlength="32" clearable></el-input>-->

                <el-radio-group :disabled="index==0" v-model="form.containerSize" class="" style="width:250px" size="mini">
                  <el-radio label="20GP">20GP</el-radio>
                  <el-radio label="40GP">40GP</el-radio>
                  <el-radio label="40HC">40HC</el-radio>
                </el-radio-group>
                <!--<template slot="error" slot-scope="scope">-->
                <!--<div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
                <!--</template>-->
              </el-form-item>
              <el-form-item :label="$t('pageTable.containerNo')" prop="containerNo">
                <el-input :disabled="index==0" v-model="form.containerNo" class="search-form-item-input" style="width:160px" size="mini"
                          :maxlength="32" clearable></el-input>
                <!--<template slot="error" slot-scope="scope">-->
                <!--<div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
                <!--</template>-->
              </el-form-item>

              <el-form-item :label="$t('pageTable.MatterSupplierName')" prop="supplierName">
                <el-input :disabled="index==0" v-model="form.supplierName" class="search-form-item-input" style="width:160px" size="mini"
                          :maxlength="32" clearable></el-input>
                <!--<template slot="error" slot-scope="scope">-->
                <!--<div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
                <!--</template>-->
              </el-form-item>
              <el-form-item :label="$t('pageTable.MatterCompany')" prop="unit">
                <el-select :disabled="index==0"  v-model="form.unit" style="width: 160px" size="mini" clearable>
                  <el-option value=""></el-option>
                  <el-option
                    size="mini"
                    v-for="item in unit"
                    :key="item.value"
                    :label="item.name"
                    :value="item.value">
                  </el-option>
                </el-select>
                <!--<template slot="error" slot-scope="scope">-->
                <!--<div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
                <!--</template>-->
              </el-form-item>
              <el-form-item :label="$t('pageTable.sendAmount')" prop="sendAmount" >
                <el-input :disabled="index==0" v-model="form.sendAmount" class="search-form-item-input" style="width:160px" size="mini" @blur="blurSendAmount(index)"
                          :maxlength="32" clearable ></el-input>
                <!--<template slot="error" slot-scope="scope">-->
                <!--<div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
                <!--</template>-->
              </el-form-item>
              <el-form-item :label="$t('pageTable.price')" prop="price">
                <el-input :disabled="true" v-model="form.price" class="search-form-item-input" style="width:160px" size="mini" @blur="blurPrice(index)"
                          :maxlength="32" clearable></el-input>
                <!--<template slot="error" slot-scope="scope">-->
                <!--<div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
                <!--</template>-->
              </el-form-item>
              <el-form-item :label="$t('pageTable.amount')" prop="amount">
                <el-input :disabled="index==0" v-model="form.amount" class="search-form-item-input" style="width:160px" size="mini"
                          :maxlength="32" clearable></el-input>
                <!--<template slot="error" slot-scope="scope">-->
                <!--<div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
                <!--</template>-->
              </el-form-item>
              <el-form-item :label="$t('pageTable.payment')" prop="payment">
                <el-select :disabled="index==0"  v-model="form.payment" style="width: 160px" size="mini" clearable>
                  <el-option value=""></el-option>
                  <el-option
                    size="mini"
                    v-for="item in payment"
                    :key="item.value"
                    :label="item.name"
                    :value="item.value">
                  </el-option>
                </el-select>
                <!--<template slot="error" slot-scope="scope">-->
                <!--<div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
                <!--</template>-->
              </el-form-item>
              <el-form-item :label="$t('pageTable.paymentDay')" prop="paymentDay">
                <el-date-picker
                  v-model="form.paymentDay"
                  type="date"
                  :disabled="index==0"
                  style="width:160px"
                  value-format="yyyyMMddHHmmss">
                </el-date-picker>
                <!--<template slot="error" slot-scope="scope">-->
                <!--<div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
                <!--</template>-->
              </el-form-item>
              <el-form-item :label="$t('pageTable.paymentDate')" prop="paymentDate">
                <el-date-picker
                  v-model="form.paymentDate"
                  type="date"
                  :disabled="index==0"
                  style="width:160px"
                  value-format="yyyyMMddHHmmss">
                </el-date-picker>
                <!--<template slot="error" slot-scope="scope">-->
                <!--<div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
                <!--</template>-->
              </el-form-item>
              <el-form-item :label="$t('pageTable.dictionaryRemark')" prop="remark">
                <el-input :disabled="index==0" v-model="form.remark" class="search-form-item-input" style="width:160px" size="mini"
                          :maxlength="32" clearable></el-input>
                <!--<template slot="error" slot-scope="scope">-->
                <!--<div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
                <!--</template>-->
              </el-form-item>
              <el-form-item :label="$t('pageTable.freightPremium')" prop="freightPremium">
                <el-input :disabled="index==0" v-model="form.freightPremium" class="search-form-item-input" style="width:160px" size="mini"
                          :maxlength="32" clearable></el-input>
                <!--<template slot="error" slot-scope="scope">-->
                <!--<div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
                <!--</template>-->
              </el-form-item>
            </el-form>
          </div>

        </div>
      </el-card>
      <div class="dialogButton">
        <el-button type="primary" size="mini" :disabled="formAll.length<2"  @click="submit('form')"><i
          class="fa fa-check"></i>  {{$t('searchFrom.confirm')}}
        </el-button>
        <el-button size="mini" @click=" cancel">{{$t('searchFrom.cancel')}}</el-button>
      </div>

    </el-dialog>
  </div>
</template>

<script>
  import activityService from '@/api/warehouse/GoodsList'

  export default {
    name: "EditOrderPlan",
    props: {
      id: {},
    },
    computed: {
      title: function () {
        let entityName = this.$t('route.warehouseDelivery')
        if(this.mode === 'ADD'){return this.$t('searchFrom.add')+entityName}
        else if(this.mode === 'EDIT'){return this.$t('searchFrom.edit')+entityName}
      }
    },
    watch:{
      // formAll:{
      //   handler(newValue, oldValue) {
      //     let sendAmountNew=0;
      //     newValue.forEach((item,index)=>{
      //         sendAmountNew=sendAmountNew+(item.sendAmount && item.sendAmount || 0);
      //     })
      //     if (sendAmountNew != this.allSendAmount) {
      //
      //     }
      //   },
      //   deep:true
      // }
    },
    data() {
      return {
        dialogFormVisible: true,
        goodsStatus:[],
        unit:[],
        transportation:[],
        payment:[],
        search_keys: {},
        formAll:[],
        allSendAmount:0,
        // form: {
        //   contractNo:"",
        //   packingDate:"",
        //   departureDate:"",
        //   shippingMethods:"",
        //   billNo:"",
        //   containerSize:"",
        //   containerNo:"",
        //   supplierName:"",
        //   materialName:"",
        //   materialCode:"",
        //   unit:"",
        //   sendAmount:"",
        //   price:"",
        //   amount:"",
        //   payment:"",
        //   paymentDay:"",
        //   paymentDate:"",
        //   remark:"",
        //   freightPremium:"",
        // },
        /**表单的验证*/
        rules: {
          materialCode: [
            {required: true, message: this.$t('Tips.checkMaterialCode'), trigger: 'blur'},
            {max: 32, message: this.$t('Tips.lentghGT32'), trigger: 'blur'},
          ],
          materialName: [
            {required: false, message: this.$t('Tips.checkMaterialCode'), trigger: 'blur'},
            {max: 32, message: this.$t('Tips.lentghGT32'), trigger: 'blur'},
          ],
          contractNo: [
            {required: false, message: this.$t('Tips.checkMaterialCode'), trigger: 'blur'},
            {max: 32, message: this.$t('Tips.lentghGT32'), trigger: 'blur'},
          ],
          packingDate: [
            {required: false, message: this.$t('Tips.checkMaterialCode'), trigger: 'blur'},
            // {max: 32, message: this.$t('Tips.lentghGT32'), trigger: 'blur'},
          ],
          departureDate: [
            {required: false, message: this.$t('Tips.checkMaterialCode'), trigger: 'blur'},
            // {max: 32, message: this.$t('Tips.lentghGT32'), trigger: 'blur'},
          ],
          shippingMethods:[
            {required: true, message: "请选择运输方式", trigger: 'change'}
          ],
          billNo: [
            {required: false, message: this.$t('Tips.checkMaterialCode'), trigger: 'blur'},
            {max: 32, message: this.$t('Tips.lentghGT32'), trigger: 'blur'},
          ],
          containerSize: [
            {required: false, message: this.$t('Tips.checkMaterialCode'), trigger: 'blur'},
            {max: 32, message: this.$t('Tips.lentghGT32'), trigger: 'blur'},
          ],
          containerNo: [
            {required: false, message: this.$t('Tips.checkMaterialCode'), trigger: 'blur'},
            {max: 32, message: this.$t('Tips.lentghGT32'), trigger: 'blur'},
          ],
          supplierName: [
            {required: false, message: this.$t('Tips.checkMaterialCode'), trigger: 'blur'},
            {max: 32, message: this.$t('Tips.lentghGT32'), trigger: 'blur'},
          ],
          unit:[
            {required: true, message: this.$t('Tips.checkMaterialUnit'), trigger: 'change'}
          ],
          sendAmount:[
            {required: true, message:  this.$t('Tips.checkSendAmount'), trigger: 'blur'},
            {pattern:  /^([0-9]*)+\.{0,1}[0-9]{1,3}$/ , trigger: 'blur', message: this.$t('Tips.floatCheck'),}
          ],
          price:[
            {pattern:  /^([0-9]*)+\.{0,1}[0-9]{1,6}$/ , trigger: 'blur', message: this.$t('Tips.floatPriceCheck'),}
          ],
          amount:[
            {pattern:  /^([0-9]*)+\.{0,1}[0-9]{1,6}$/ , trigger: 'blur', message: this.$t('Tips.floatPriceCheck'),}
          ],
          payment:[
            {required: true, message: this.$t('Tips.chooseTransportation'), trigger: 'change'}
          ],
          paymentDay:[
            {required: false, message: this.$t('Tips.checkMaterialCode'), trigger: 'blur'},
            // {max: 32, message: this.$t('Tips.lentghGT32'), trigger: 'blur'},
          ],
          paymentDate:[
            {required: false, message: this.$t('Tips.checkMaterialCode'), trigger: 'blur'},
            // {max: 32, message: this.$t('Tips.lentghGT32'), trigger: 'blur'},
          ],
          remark:[
            {required: false, message: this.$t('Tips.checkMaterialCode'), trigger: 'blur'},
            {max: 32, message: this.$t('Tips.lentghGT32'), trigger: 'blur'},
          ],
          freightPremium:[
            // {required: false, message: this.$t('Tips.checkMaterialCode'), trigger: 'blur'},
            // {max: 32, message: this.$t('Tips.lentghGT32'), trigger: 'blur'},
          ],


        },
      }
    },
    mounted() {
      this.init()
    },
    methods: {
      /**
       * 加法运算，避免数据相加小数点后产生多位数和计算精度损失。
       *
       * @param num1加数1 | num2加数2
       */
      bcadd(num1, num2, s) {
        var baseNum, baseNum1, baseNum2, ret;
        try {
          baseNum1 = (''+num1).toString().split(".")[1].length;
        } catch (e) {
          baseNum1 = 0;
        }
        try {
          baseNum2 = (''+num2).toString().split(".")[1].length;
        } catch (e) {
          baseNum2 = 0;
        }
        baseNum = Math.pow(10, Math.max(baseNum1, baseNum2));
        ret = (num1 * baseNum + num2 * baseNum) / baseNum;
        return this.bcFixed(ret, s);
      },
      /**
       * 加法运算，避免数据相减小数点后产生多位数和计算精度损失。
       *
       * @param num1被减数  |  num2减数
       */
      bcsub(num1, num2, s) {
        var baseNum, baseNum1, baseNum2, ret;
        var precision;// 精度
        try {
          baseNum1 = (''+num1).toString().split(".")[1].length;
        } catch (e) {
          baseNum1 = 0;
        }
        try {
          baseNum2 = (''+num2).toString().split(".")[1].length;
        } catch (e) {
          baseNum2 = 0;
        }
        baseNum = Math.pow(10, Math.max(baseNum1, baseNum2));
        precision = (baseNum1 >= baseNum2) ? baseNum1 : baseNum2;
        ret = ((num1 * baseNum - num2 * baseNum) / baseNum).toFixed(precision);
        return this.bcFixed(ret, s);
      },
      bcmul(num1, num2, s) {
        var baseNum = 0, ret;
        try {
          baseNum += (''+num1).toString().split(".")[1].length;
        } catch (e) {
        }
        try {
          baseNum += (''+num2).toString().split(".")[1].length;
        } catch (e) {
        }
        ret = Number((''+num1).toString().replace(".", "")) * Number((''+num2).toString().replace(".", "")) / Math.pow(10, baseNum);
        if ( this.bcFixed(ret, s) =='false'){
          return ""
        } else {
          return this.bcFixed(ret, s);
        }

      },
      toDecimal2(x, ss) {
        var f = parseFloat(x);
        if (isNaN(f)) {
          return false;
        }
        var f = Math.round(x * 100) / 100;
        var s = f.toString();
        var rs = s.indexOf('.');
        if (rs < 0) {
          rs = s.length;
          s += '.';
        }
        while (s.length <= rs + ss) {
          s += '0';
        }
        return s && s|| "";
      },

      bcFixed(num, s) {
        var times = Math.pow(10, s)
        var des = num * times + 0.5
        des = parseInt(des, 10) / times
        return this.toDecimal2(des, s) + '';
      },
      addOne(){
        let objectA=JSON.parse(JSON.stringify(this.formAll[0]));
        objectA['sendAmount']='';
        this.formAll.push(objectA)  ;
      },
      deleteOne(index){
        this.formAll[0].sendAmount=parseInt(this.formAll[0].sendAmount) +parseInt((this.formAll[index].sendAmount && this.formAll[index].sendAmount || 0)) ;
        this.formAll[0].amount=this.bcmul(this.formAll[0].price,this.formAll[0].sendAmount,2);

        this.formAll.splice(index,1)
      },
      initInfoByContractNo(contractNo,index){
        activityService.initInfoByContractNo({contractNo}).then(resp=>{
          if (resp.data.code == 200){
            this.formAll[index].billNo =resp.data.result.billNo;
            this.formAll[index].packingDate=resp.data.result.packingDate;
            this.formAll[index].departureDate=resp.data.result.departureDate;
            this.formAll[index].paymentDay=resp.data.result.paymentDay;
            this.formAll[index].paymentDate=resp.data.result.paymentDate;
          } else {
            this.$notify({message: resp.data.message, type: "error"});
          }
        },error => {

        })
      },
      blurDepartureDate(index){
        this.formAll[index].paymentDay= this.formAll[index].departureDate && this.$moment( this.formAll[index].departureDate,'YYYYMMDDHHmmss').add(30, 'days').format('YYYYMMDDHHmmss')|| "";

      },
      blurSendAmount(index){
        // this.formAll[index].amount=this.formAll[index].price*this.formAll[index].sendAmount;
        if (this.formAll[index].sendAmount == '' || this.formAll[index].sendAmount == null){
          this.formAll[index].sendAmount = 0
        }
        this.formAll[index].amount=this.bcmul(this.formAll[index].price,this.formAll[index].sendAmount,2);
        // this.formAll[0].sendAmount=this.formAll[0].sendAmount-this.formAll[index].sendAmount;

        let a=0;
        this.formAll.forEach((item,index1)=>{
          if (index1!=0){
            a=parseInt(a)+parseInt(item.sendAmount)
          }
        });
        this.formAll[0].sendAmount=this.allSendAmount-a;
        this.formAll[0].amount=this.bcmul(this.formAll[0].price,this.formAll[0].sendAmount,2);
      },
      blurPrice(index){
        // this.formAll[index].amount=this.formAll[index].price*this.formAll[index].sendAmount;
        this.formAll[index].amount=this.bcmul(this.formAll[index].price,this.formAll[index].sendAmount,2);

      },
      async init() {
         await  activityService.initView().then(resp=>{
           this.goodsStatus=resp.data.result.goodsStatus;
           this.transportation=resp.data.result.transportation;
           this.payment=resp.data.result.payment;
           this.unit=resp.data.result.unit;
        },error => {

        })
        await activityService.getDeliverInfo({id: this.id}).then(resp => {
          this.formAll.push(resp.data.result)  ;
          this.allSendAmount=this.formAll[0].sendAmount;
        }, err => {
          console.error(err);
        });

      },
      async selectMaterialInfo(materialCode,index){
        await activityService.selectMaterialInfo({materialCode:materialCode}).then(resp=>{
          if (resp.data.code == "201") {
              this.formAll[index].unit=resp.data.result.materialUnit;
              this.formAll[index].supplierName=resp.data.result.supplierNameCn;
              this.formAll[index].materialName=resp.data.result.materialDescCn;
              this.formAll[index].price = resp.data.result.materialPrice;
          } else {
            this.formAll[index].unit="";
            this.formAll[index].supplierName="";
            this.formAll[index].materialName="";
            this.$notify({message: resp.data.message, type: "error"});
          }
        })
      },
      /*确定*/
      submit(formName) {
        let arrayPromise = [];
        let list = this.$refs[formName];
        list.forEach(item => {
          let p = new Promise((resolve, reject) => {
            item.validate((valid) => {
              if (valid) {
                resolve();
              }
            })
          });
          arrayPromise.push(p)
        });
        Promise.all(arrayPromise).then( ()=> {
          // alert("验证通过了");

          // let all=this.formAll[0].sendAmount;
          // let sum=0;
          let tDeliverInfoEntityList=[];
          this.formAll.forEach((item,index)=>{
            // if (index==0){

            // } else {
              let objectResult={
                contractNo                :item.contractNo                 || undefined,
                packingDate               :item.packingDate                || undefined,
                departureDate             :item.departureDate              || undefined,
                shippingMethods           :item.shippingMethods            || undefined,
                billNo                    :item.billNo                     || undefined,
                containerSize             :item.containerSize              || undefined,
                containerNo               :item.containerNo                || undefined,
                supplierName              :item.supplierName               || undefined,
                materialName              :item.materialName               || undefined,
                materialCode              :item.materialCode               || undefined,
                unit                      :item.unit                       || undefined,
                sendAmount                :item.sendAmount                 || undefined,
                price                     :item.price                      || undefined,
                amount                    :item.amount                     || undefined,
                payment                   :item.payment                    || undefined,
                paymentDay                :item.paymentDay                 || undefined,
                paymentDate               :item.paymentDate                || undefined,
                remark                    :item.remark                     || undefined,
                freightPremium            :item.freightPremium             || undefined,
              }
              tDeliverInfoEntityList.push(objectResult);
              // sum=sum+item.sendAmount
            // }
          });
          let flag = false;
          tDeliverInfoEntityList.forEach(item=>{
            if (item.sendAmount == 0 || item.sendAmount == null) {
              this.$notify({message: '您填写的发货数量有0或者空，请您检查', type: "error"});
                flag=true
            }
          });
          if (flag){
            return
          }
          // if (all<sum) {
          //   this.$notify({message: '您拆分的发货数量大于了这条数据的总发货数量，请您检查', type: "error"});
          //   return
          // }
          let objectA={
            id:this.id,
            tDeliverInfoEntity:tDeliverInfoEntityList,
          };
          activityService.splitGoods({...objectA}).then(resp => {  //添加
            if (resp.data.code == "201") {
              this.$notify({message: resp.data.message, type: "success"});
              this.$emit("success");
              this.dialogFormVisible = false
            } else {
              this.$notify({message: resp.data.message, type: "error"});
            }
          })


        });



        // this.$refs[formName].validate((valid) => {
        //   if (valid) {
        //
        //   } else {
        //     console.log('error submit!!');
        //     return false;
        //   }
        // });
      },
      cancel() {
        this.dialogFormVisible = false
      },
    }
  }
</script>

<style scoped>

</style>